﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Net;


namespace LibIpMsgNet
{
    public class THostSub
    { 
        public string UserName;// = new char[Consts.MAX_NAMEBUF];
        public string HostName;// = new char[Consts.MAX_NAMEBUF];
        //public ulong Address;
        //public int PortNo;
        public IPEndPoint EndPoint;

        public THostSub()
        {
            EndPoint = new IPEndPoint(IPAddress.Any, 65535);
        }
    }

    public class THost
    {
        public THostSub hostSub;
        public string nickName;// = new char[Consts.MAX_NAMEBUF];
        public string groupName;// = new char[Consts.MAX_NAMEBUF];
        public ulong hostStatus;
        //public time_t updateTime;
        public Int64 updateTime;
        public int priority;
        public int refCnt;
        //public PubKey pubKey;
        public int cryptSpec;

        public THost() 
        { 
            refCnt = 0; 
        }

        ~THost() 
        { 
            refCnt = 0; 
        }

        public int RefCnt(int cnt) 
        { 
            return refCnt += cnt; 
        }

        public int RefCnt() 
        {
            return refCnt;
        }
    }

    /*
    public class THosts
    { 
	    public enum Kind 
        { NAME, ADDR, NAME_ADDR, MAX_ARRAY };

	    public bool[] enable = new bool[(int)Kind.MAX_ARRAY];
	    protected int hostCnt;
        protected Host[,] array = new Host[(int)Kind.MAX_ARRAY, (int)Kind.MAX_ARRAY];

        public THosts() 
        {
            hostCnt = 0;
            for (int kind = 0; kind < (int)Kind.MAX_ARRAY; kind++)
		        enable[kind] = false;
        }

	    ~THosts() 
        {
        }

        protected Host Search(Kind kind, HostSub hostSub, int insertIndex)
        {
            int min = 0, max = hostCnt - 1, cmp, tmpIndex;

            if (insertIndex == null)
                insertIndex = &tmpIndex;

            while (min <= max)
            {
                *insertIndex = (min + max) / 2;

                if ((cmp = Cmp(hostSub, &array[kind][*insertIndex]->hostSub, kind)) == 0)
                    return array[kind][*insertIndex];
                else if (cmp > 0)
                    min = *insertIndex + 1;
                else
                    max = *insertIndex - 1;
            }

            *insertIndex = min;

            return null;
        }

        protected Host Search(Kind kind, HostSub hostSub) // insertIndex=NULL
        { 
        }

        protected int Cmp(HostSub hostSub1, HostSub hostSub2, Kind kind)
        { 
        }


	    public void	Enable(Kind kind, bool _enable) 
        {
            enable[(int)kind] = _enable; 
        }

	    public bool	AddHost(Host host)
        {
            int[] insertIndex = new int[(int)Kind.MAX_ARRAY];

            for (Kind kind = Kind.NAME; kind < Kind.MAX_ARRAY; kind++)
            {
                if (enable[(int)kind] == false)
			        continue;
                if (Search((Kind)kind, host->hostSub, &insertIndex[(int)kind]) != null)
			        return	false;
	        }
        }

	    public bool	DelHost(Host host)
        {
        }

	    public int HostCnt() 
        { 
            return hostCnt; 
        }

	    public Host	GetHost(int index, Kind kind) 
        { 
            return array[(int)kind, index]; 
        }

        public Host	GetHost(int index) 
        {
            return array[(int)Kind.NAME, index];
        }

	    public Host	GetHostByName(HostSub hostSub) 
        {
            return enable[(int)Kind.NAME] ? Search(Kind.NAME, hostSub) : null; 
        }

	    public Host	GetHostByAddr(HostSub hostSub) 
        {
            return enable[(int)Kind.ADDR] ? Search(Kind.ADDR, hostSub) : null; 
        }

	    public Host	GetHostByNameAddr(HostSub hostSub) 
        {
            return enable[(int)Kind.NAME_ADDR] ? Search(Kind.NAME_ADDR, hostSub) : null; 
        }

        public int PriorityHostCnt(int priority, int range)
        { 
        }

        public int PriorityHostCnt(int priority) // range = 1
        {
        }
    }
     * */
}
